/****************************************************************
** Tutorial_Arduino_Pot_LED_Control                      
**
** Original Author:      Sammy_K
** Webpage:              www.dreamgineer.org
**
** Project:              Dreamgineer Tutorials: Arduino
** Written On:           May 2012
** Last Updated:         May 2012
**
** A Simple Example That Demonstrates How To Control The
** Brightness Of An LED Based On The Position Of A Potentiometer
**
****************************************************************/

//Declare Variables
unsigned int potVal;

/****************************************************************
** setup() - Executes Once On Boot
**
** Set DIO PIN 11 As Output To Drive Discrete LED Using PWM
**
****************************************************************/
void setup()
{
  pinMode(11, OUTPUT);  //Configure Pin 11 As Output To Drive LED
}

/****************************************************************
** loop() - Executes Repeatadly After setup() returns.
**
** The Loop Function Reads The Analog Output From The Pot, Scales
** It To 0-255, Then Uses It To Update The Duty Cycle Of The
** PWM Signal Driving The LED.
**
****************************************************************/
void loop()
{
  potVal = analogRead(0);  //Read Pot Value (10-Bit Number)
  potVal = potVal >> 2;    //Right Shift 2 Bits To Get 8 Bit Value
  analogWrite(11, potVal); //Update PWM Duty Cycle
}


/****************************************************************
** Copyright (c) Dreamgineer.org
**
** Permission to use, copy, modify, and distribute this software 
** for any purpose with or without fee is hereby granted, 
** provided that the above copyright notice and this permission 
** notice appear in all copies. 
**
** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 
** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 
** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL 
** THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
** CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
** FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF 
** CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
** OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
****************************************************************/
